package com.snail.auth.action;

import com.common.ResultUtil;
import com.common.entity.BaseController;
import com.common.entity.Page;
import com.snail.auth.entity.AuthRoleGroup;
import com.snail.auth.service.AuthRoleGroupService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "角色分组")
@RestController
@RequestMapping("/auth/roletype")
public class AuthRoleGroupController extends BaseController {

    @Autowired
    private AuthRoleGroupService roleGroupService;

    @GetMapping
    public Map<String, Object> list() {
        Map<String, Object> params = new HashMap<>();
        params.put("keyword", request.getParameter("keyword"));
        List<Map<String, Object>> list = roleGroupService.list(params);
        return ResultUtil.result(list);
    }

    @GetMapping(value = "/page")
    public Map<String, Object> page(Page page) {
        Map<String, Object> params = new HashMap<>();
        params.put("keyword", request.getParameter("keyword"));
        page = roleGroupService.page(page, params);
        return ResultUtil.result(page);
    }

    @GetMapping(value = "/{id}")
    public Map<String, Object> input(@PathVariable Long id) {
        AuthRoleGroup entity = roleGroupService.getByKey(id);
        return ResultUtil.result(entity);
    }

    @PostMapping
    public Map<String, Object> save(AuthRoleGroup entity) {
        roleGroupService.save(entity);
        return ResultUtil.result(entity);
    }

    @DeleteMapping(value = "/{id}")
    public Map<String, Object> del(@PathVariable Long id) {
        roleGroupService.del(id);
        return ResultUtil.result();
    }
}
